﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Xml;
using System.Reflection;
using System.Globalization;
using System.Threading;


namespace KHAMBENH
{
    public class Modules
    {
        public static int nam, thang;
        public enum ClickButtonStatus
        {
            Them = 0,
            Sua = 1,
            Ghi = 2,
            Ngung = 3

        };
        public static void SendKey(Form frm, KeyEventArgs e)
        {

            try
            {

                if (((((e.KeyCode == Keys.Return) & !e.Alt) & !e.Control) & !e.Shift) && !((frm.ActiveControl.Parent is C1.Win.C1FlexGrid.C1FlexGrid) | (frm.ActiveControl is C1.Win.C1FlexGrid.C1FlexGrid)))
                {

                    if (frm.GetNextControl(frm.ActiveControl, true) != null)
                    {
                        if (frm.ActiveControl.Name != "cboThuoc")
                        {
                            SendKeys.Send("{TAB}");
                        }
                    }
                    else
                    {
                        while (frm.GetNextControl(frm.ActiveControl, true) == null)
                        {

                            if (!frm.GetNextControl(frm.ActiveControl, true).Enabled)
                            {
                                frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                            }
                            else
                            {
                                if (!frm.GetNextControl(frm.ActiveControl, true).Visible)
                                {
                                    if (frm.GetNextControl(frm.ActiveControl, true) is TabPage)
                                    {
                                        frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                        return;
                                    }
                                    frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is GroupBox)
                                {
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is TabControl)
                                {
                                    frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is TabPage)
                                {
                                    frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is RadioButton)
                                {
                                    if (frm.ActiveControl is RadioButton)
                                    {
                                        SendKeys.Send("{TAB}");
                                    }
                                    else
                                    {
                                        frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    }
                                    return;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is Label)
                                {
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                }
                                else
                                {
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception1)
            {

                Exception exception = exception1;
                throw exception;

            }
        }
        public static string ChangeToCamel(string str)
        {
            string[] strArr = str.Split(new char[] { ' ' });
            StringBuilder strTemp = new StringBuilder();

            foreach (string subStr in strArr)
            {
                if (subStr != "")
                {
                    if (subStr.Substring(0, 1) != "ñ")
                    {
                        strTemp.Append(subStr.Substring(0, 1).ToUpper()).Append(subStr.Substring(1, subStr.Length - 1)).Append(" ");
                    }
                    else
                    {
                        strTemp.Append(subStr.Substring(0, 1)).Append(subStr.Substring(1, subStr.Length - 1)).Append(" ");
                    }
                }
            }
            return strTemp.ToString();
        }
        public static String CreateRunninNo(Random rnd)
        {
            //Char vt1;
            //, vt2, vt3;
            string st;
            DateTime date = DateTime.Now;
            //vt1 = RandomChar(rnd);
            //vt2 = RandomChar(rnd);
            //vt3 = RandomChar(rnd);
            st = String.Format("{0:000}", DateTime.Now.Millisecond) + String.Format("{0:00}", rnd.Next(0, 99));
            return DateTime.Now.Year.ToString().Substring(2) +
                String.Format("{0:00}", date.Month) +
                String.Format("{0:00}", date.Day) +
                String.Format("{0:00}", date.Hour) +
                String.Format("{0:00}", date.Minute) +
                String.Format("{0:00}", date.Second) +
                st;//+ vt1;
        }
        
    }
}
